<?php

function tree_print_1($a_tree){

if(empty($a_tree)) return;
 $ul = "<ul";
if(!empty($a_tree[0]['idul'])) $ul .= ' id="'.$a_tree[0]['idul'].'"';
if(!empty($a_tree[0]['ucls'])) $ul .= ' class="'.$a_tree[0]['ucls'].'"';
 echo $ul.">";

  for($i=0;$i< count($a_tree);$i++){

     $li = "<li";
if(!empty($a_tree[$i]['idli'])) $li .= ' id="'.$a_tree[$i]['idli'].'"';
if(!empty($a_tree[$i]['lcls'])) $li .= ' class="'.$a_tree[$i]['lcls'].'"';

	  $li.='><a href="';
if(!empty($a_tree[$i]['lnk'])){$li.= $a_tree[$i]['lnk'].'"';}else{$li.='#"';}
if(!empty($a_tree[$i]['idht'])) $li .= ' id="'.$a_tree[$i]['idht'].'"';
if(!empty($a_tree[$i]['hcls'])) $li .= ' class="'.$a_tree[$i]['hcls'].'"';
	   $li .= '><span>'.$a_tree[$i]['name'].'</span></a>';
	 echo $li;

 if(!empty($a_tree[$i]['children'])){
 tree_print($a_tree[$i]['children']);
 echo "</li>";
 }

 }
   echo "</li>";
   echo "</ul>";
}

function mk_tree_arr($r){
global $wpdb,$table_prefix;

$mesql = "SELECT mendata FROM ".$table_prefix."wddmenu WHERE mename='$r'";
 $frez = $wpdb ->  get_results($mesql,ARRAY_A);
  $mestr = $frez[0]['mendata'];
   $menarr = json_decode($mestr,true);
$menarr = (array)$menarr;
for ($m=0;$m<count($menarr);$m++){
   echo "<ul>";
    tree_print($menarr[$m]);
   echo "</ul>";
 }
}


function tree_print($a_tree){
if(empty($a_tree)) return;
  $li = "<li";
if(!empty($a_tree['idli'])) $li .= ' id="'.$a_tree[$i]['idli'].'"';
if(!empty($a_tree['lcls'])) $li .= ' class="'.$a_tree[$i]['lcls'].'"';

$li .="><a href='".$a_tree['lnk']."'><span>".$a_tree['name']."</span></a>";
echo $li;

   if(!empty($a_tree['children'])){
   echo '<ul>';
    for($k=0;$k<count($a_tree['children']);$k++){
   tree_print($a_tree['children'][$k]);
       }
       echo "</ul></li>";
    }else{
    echo "</li>";
}
}
?>